#include <iostream>
using std::cout;
using std::endl;

void swap(int x, int y){//值传递，发生复制
    int temp = x;
    x = y;
    y = temp;
}

void swap2(int * px, int * py)//地址传递
{
    int temp = *px;
    *px = *py;
    *py = temp;
}

//调用swap3时传入两个int型的参数a,b
//实际就是利用实参a,b初始化形参x,y
//int & x = a;
//int & y = b;
//在函数体中对引用进行修改操作
//会直接修改引用所绑定的变量本体
void swap3(int & x, int & y){//引用传递
    int temp = x;
    x = y;
    y = temp;
}


void test0(){
    int a = 1, b = 2;
    swap3(a,b);
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;
}

void test1(){
    int a = 1, b = 2;
    swap2(&a,&b);
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;
}




int main(void){
    test0();
    return 0;
}
